﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using YJYpublicClass;

namespace YJYpublicClass
{
    public partial class Frm_DS相机设置 : Form
    {
        CameraDS2 tempdev = null;
        public Frm_DS相机设置(CameraDS2 obj)
        {
            InitializeComponent();
            this.tempdev=obj;
        }

        private void btn_保存设置_Click(object sender, EventArgs e)
        {
            string path = tempdev.Savepath + ".xml";
            if (XmlHelper.SaveXML(path, tempdev) == "")
            {
                MessageBox.Show("数据保存成功");
            }
            else
            {
              
                MessageBox.Show("数据保存失败");
            }
        }

        private void btn_设置曝光_Click(object sender, EventArgs e)
        {
            try
            {
                if (tempdev.SetExposuretime(tempdev.Exposuretime))
                {
                    MessageBox.Show("曝光设置成功");
                }
                else
                {
                    MessageBox.Show("曝光设置失败");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("曝光设置失败:" + ex.Message);
            }

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            // this.imageBox1.Image = tempdev.Image;
            //  PublicFuntions.DispImage(tempdev.Image, hWindowControl1.HalconWindow);

            if (cbx_更新.Checked)
            {
                this.propertyGrid1.SelectedObject = tempdev;
            }
            lab_zhenlv.Text = tempdev.zhenlv.ToString("0.00");
            lab_耗时.Text = tempdev.haoshi.ToString();
        }

        private void btn_打开相机_Click(object sender, EventArgs e)
        {
            try
            {
                tempdev.OpenCamerabyname(tempdev.CameraSNname);
                richTextBox1.AppendText("完成" + "\r\n");
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            }
        }

        private void btn_关机相机_Click(object sender, EventArgs e)
        {
            try
            {
                tempdev.CloseCamera();
                richTextBox1.AppendText("完成" + "\r\n");
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            }
        }

        private void btn_开始取图_Click(object sender, EventArgs e)
        {
            tempdev.StartGrab();
            richTextBox1.AppendText("完成" + "\r\n");
        }

        private void btn_停止取图_Click(object sender, EventArgs e)
        {
            tempdev.StopGrab();
            richTextBox1.AppendText("完成" + "\r\n");
        }

        private void btn_查询_Click(object sender, EventArgs e)
        {
            CameraDS2.Enumdevlist();
            foreach (var item in CameraDS2.CameraSnNames)
            {
                comboBox1.Items.Add(item);
            }
            richTextBox1.AppendText("查询完成" + "\r\n");
        }

        private void Frm_DS相机设置_Load(object sender, EventArgs e)
        {
            this.propertyGrid1.SelectedObject = tempdev;
            timer1.Enabled = true;
            tempdev.PictureBox1 =pictureBox1;
        }

        private void btn_ReverseY_Click(object sender, EventArgs e)
        {
            
            richTextBox1.AppendText("完成" + "\r\n");
        }

        private void btn_gain_Click(object sender, EventArgs e)
        {
            try
            {
                if (tempdev.setGain(tempdev.Gain))
                {
                    MessageBox.Show("增益设置成功");
                }
                else
                {
                    MessageBox.Show("增益设置失败");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("增益设置失败:" + ex.Message);
            }
        }
    }
}
